#include <bits/stdc++.h>
using namespace std;
int n,t,lp,lk,cnt=0;
int a[2000006],ls[200006];
int ans;
void dfs(int x){
    if(x==n+1){
        cnt=0,lp=0,lk=0;
        for(int i=1;i<=n;i++){
            if(ls[i]==0){
                if(a[lp]==a[i]){
                    cnt+=a[i];
                }
                lp=i;
            }
            else{
                if(a[lk]==a[i]){
                    cnt+=a[i];
                }
                lk=i;
            }
        }
        ans=max(ans,cnt);
        return;
    }
    ls[x]=1;
    dfs(x+1);
    ls[x]=0;
    dfs(x+1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int k=1;k<=t;k++){
        cin>>n;
        ans=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        dfs(1);
        cout<<ans<<endl;
    }
    return 0;
}
